package com.epam.debrecen.hackathon.ai.model;

import java.util.LinkedList;
import java.util.List;

public class GameStateImplementation extends GameState {

	@Override
	public void occupy(String city) {
		occupiedCities.add(city);
	}

	@Override
	public void protect(String city) {
		protectedCity = city;
	}

	@Override
	public void setCurrentZone(String city) {
		currentZone = city;
	}

	@Override
	public void dealCards(List<String> cards) {
		hand = cards;
	}

	@Override
	public void playCard(String card) {
		battleLines.get(currentPlayer).add(card);
	}

	@Override
	public void pass(String pass) {
	}

	@Override
	public void discardBattleLines() {
		for(List<String> battleLine : battleLines.values()){
			battleLine.clear();
		}
	}

	@Override
	public void discardHand() {
		hand.clear();
	}

	@Override
	public void startGame() {
	}

	@Override
	public void startRound() {
		round++;
	}

	@Override
	public void startBattle() {
		battle++;
	}

	@Override
	public void endBattle(String winner) {
		if(!"tie".equals(winner)){
			occupiedCities.add(currentZone);
		}
		currentZone = null;
		discardBattleLines();
		discardHand();
	}

	@Override
	public void endRound() {
	}

	@Override
	public void endGame() {
	}

	@Override
	public void setCurrentPlayer(String player) {
		currentPlayer = player;
	}

	@Override
	public void setPlayers(List<String> players) {
		this.players = players;
		for(String player : players){
			battleLines.put(player,new LinkedList<String>());
			scores.put(player, 0);
		}
	}

	@Override
	public void score(String player, int score) {
		scores.put(player, score);
	}

	@Override
	public void setOrder(List<String> order) {
		this.order = order;
	}

	@Override
	public String replyAttackedZone() {
		return ai.replyAttackedZone(occupiedCities, protectedCity);
	}

	@Override
	public String replySelectedCard() {
		return ai.replySelectedCard(hand, battleLines);
	}

	@Override
	public String replyProtectedZone() {
		return ai.replyProtectedZone(occupiedCities);
	}

	@Override
	public String replyRetrievedCard() {
		return ai.replyRetrievedCard(hand, battleLines);
	}



}
